package com.santu.edu.supporter.biz.good.pojo.dto;

import com.santu.edu.supporter.biz.good.pojo.params.GoodAddParam;
import com.santu.edu.supporter.biz.good.pojo.params.GoodUpdateParam;
import com.santu.edu.supporter.biz.good.pojo.po.GoodPO;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * @author luoyaoqi
 * @createTime 2024/3/12
 * @description
 */
@Data
@Accessors(chain = true)
public class GoodDTO {
    /**
     * 商品id
     */
    private String goodId;

    /**
     * 类别id
     */
    private String categoryId;

    /**
     * 商品名称
     */
    private String goodName;

    /**
     * 商品价格
     */
    private BigDecimal price;

    /**
     * 商品图片
     */
    private String imageUrl;

    /**
     * 商品描述
     */
    private String description;

    /**
     * 商品数量
     */
    private Integer goodNum;

    /**
     * 商品状态[0:停售,1起售]
     */
    private Integer goodStatus;

    /**
     * 商品顺序
     */
    private Integer goodSort;

    public static GoodDTO createItem(String goodId, GoodAddParam addParam) {
        return new GoodDTO()
                .setGoodId(goodId)
                .setCategoryId(addParam.getCategoryId())
                .setGoodName(addParam.getGoodName())
                .setPrice(addParam.getPrice())
                .setImageUrl(addParam.getImageUrl())
                .setDescription(addParam.getDescription())
                .setGoodNum(addParam.getGoodNum())
                .setGoodStatus(addParam.getGoodStatus())
                .setGoodSort(addParam.getGoodSort());
    }

    public static GoodDTO createItem(GoodUpdateParam updateParam) {
        return new GoodDTO()
                .setGoodId(updateParam.getGoodId())
                .setCategoryId(updateParam.getCategoryId())
                .setGoodName(updateParam.getGoodName())
                .setPrice(updateParam.getPrice())
                .setImageUrl(updateParam.getImageUrl())
                .setDescription(updateParam.getDescription())
                .setGoodNum(updateParam.getGoodNum())
                .setGoodStatus(updateParam.getGoodStatus())
                .setGoodSort(updateParam.getGoodSort());
    }

    public static GoodDTO createItem(GoodPO item) {
        return new GoodDTO()
                .setGoodId(item.getGoodId())
                .setCategoryId(item.getCategoryId())
                .setGoodName(item.getGoodName())
                .setPrice(item.getPrice())
                .setImageUrl(item.getImageUrl())
                .setDescription(item.getDescription())
                .setGoodNum(item.getGoodNum())
                .setGoodStatus(item.getGoodStatus())
                .setGoodSort(item.getGoodSort());
    }
}
